//
//  UIButton+Extension.swift
//  sinaweibowj
//
//  Created by Macintosh on 15/12/18.
//  Copyright © 2015年 mactoinsh. All rights reserved.
//

import UIKit


//便利的构造函数，实例化UIBUtton

extension UIButton{
    
    //实例化有背景视图 + title的自定义按钮
    convenience init(title:String, backgroundImage:String?,fontSize:CGFloat,color:UIColor,imageName:String? = nil){
        //需要调用本类的制定构造函数实例化自己
        self.init()
        
        setTitle(title, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(color, forState: .Normal)
        if imageName != nil {
        
            setImage(UIImage(named: imageName!), forState: .Normal)
        }
        if backgroundImage != nil {
        
        setBackgroundImage(UIImage(named: backgroundImage!), forState: .Normal)
        }
        
        sizeToFit()
    }
    
    //实例化有背景视图 + image按钮的样式
    convenience init(imageName:String? = nil,backgroundImageName:String){
    
    self.init()
    
        if imageName != nil {
        setImage(UIImage(named: imageName!), forState: .Normal)
        setImage(UIImage(named: imageName!+"_highlighted"), forState: .Highlighted)
        }
        setBackgroundImage(UIImage(named: backgroundImageName), forState: .Normal)
        setBackgroundImage(UIImage(named:backgroundImageName + "_highlighted"), forState: .Highlighted)
        
        sizeToFit()

    }
    
    
}